class ProductsController < ApplicationController

  before_action :set_product, only: [:show]

  def index
    @first_product = Product.ordered_products.first
    @products = Product.ordered_products.where.not(id: @first_product.id).page(params[:page])
  end

  def show
    @order = Order.new
    @uploads = @product.uploads
  end

  def list
    @products = Product
    @products = @products.where(category: params[:category])
    @products = @products.where("tags like ? or tags like ? or tags like ? or tags = ?","%,#{params[:tag]},%","%,#{params[:tag]}","#{params[:tag]},%",params[:tag])
    @products = @products.published.page(params[:page])
    # redirect_to @products.first if @products.present?
  end

  private

    def set_product
      @product = Product.find(params[:id])
    end

end